﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Warensoft.PythonExtension
{
    public static class PythonExtension
    {
        public delegate void CallBack<T>(ref  T param1);
        public delegate void CallBack<T, U>(ref  T param1, ref  U param2);
        public delegate void CallBack<T, U, V>(ref  T param1, ref U param2, ref V param3);
        public delegate void CallBack<T, U, V, A>(ref  T param1, ref U param2, ref V param3, ref A param4);
        //public delegate void CallBack<T, U, V, A, B>(ref  T param1, ref U param3, ref V param3, ref A param4, ref B param5);
        /// <summary>
        /// 对Python进行For循环
        /// </summary>
        /// <typeparam name="T">第一个参数类型</typeparam>
        /// <param name="start">循环开始值</param>
        /// <param name="to">循环结束值</param>
        /// <param name="step">步长</param>
        /// <param name="param1">第一个参数</param>
        /// <param name="CallBack">Python回调函数</param>
        public static void For<T>(long start, long to, long step, ref T param1, CallBack<T> CallBack)
        {
            for (long i = start; i < to; i += step)
            {
                CallBack(ref param1);
            }
        }
        /// <summary>
        /// 对Python进行For循环
        /// </summary>
        /// <typeparam name="T">第一个参数类型</typeparam>
        /// <typeparam name="U">第二个参数类型</typeparam>
        /// <param name="start">循环开始值</param>
        /// <param name="to">循环结束值</param>
        /// <param name="step">步长</param>
        /// <param name="param1">第一个参数</param>
        /// <param name="param2">第二个参数</param>
        /// <param name="CallBack">Python回调函数</param>
        public static void For<T, U>(long start, long to, long step, ref T param1,ref  U param2, CallBack<T, U> CallBack)
        {
            for (long i = start; i < to; i += step)
            {
                CallBack(ref param1,ref  param2);
            }
        }
        /// <summary>
        /// 对Python进行For循环
        /// </summary>
        /// <typeparam name="T">第一个参数类型</typeparam>
        /// <typeparam name="U">第二个参数类型</typeparam>
        /// <typeparam name="A">第三个参数类型</typeparam>
        /// <param name="start">循环开始值</param>
        /// <param name="to">循环结束值</param>
        /// <param name="step">步长</param>
        /// <param name="param1">第一个参数</param>
        /// <param name="param2">第二个参数</param>
        /// <param name="param3">第三个参数</param>
        /// <param name="CallBack">Python回调函数</param>
        public static void For<T, U, A>(long start, long to, long step, ref T param1,ref  U param2, ref  A param3, CallBack<T, U, A> CallBack)
        {
            for (long i = start; i < to; i += step)
            {
                CallBack(ref param1,ref  param2,ref param3);
            }
        }
        /// <summary>
        /// 对Python进行For循环
        /// </summary>
        /// <typeparam name="T">第一个参数类型</typeparam>
        /// <typeparam name="U">第二个参数类型</typeparam>
        /// <typeparam name="A">第三个参数类型</typeparam>
        /// <typeparam name="B">第四个参数类型</typeparam>
        /// <param name="start">循环开始值</param>
        /// <param name="to">循环结束值</param>
        /// <param name="step">步长</param>
        /// <param name="param1">第一个参数</param>
        /// <param name="param2">第二个参数</param>
        /// <param name="param3">第三个参数</param>
        /// <param name="param4">第四个参数</param>
        /// <param name="CallBack">Python回调函数</param>
        public static void For<T, U, A, B>(long start, long to, long step, ref T param1,ref  U param2, ref  A param3, ref  B param4, CallBack<T, U, A, B> CallBack)
        {
            for (long i = start; i < to; i += step)
            {
                CallBack(ref param1,ref param2,ref param3,ref  param4);
            }
        }

        /// <summary>
        /// 对Python进行For循环
        /// </summary>
        /// <param name="start">开始值</param>
        /// <param name="to">结束值</param>
        /// <param name="step">步长</param>
        /// <param name="CallBack">Python回调</param>
        public static void For(long start, long to, long step, Action  CallBack)
        {
            for (long i = start; i < to; i += step)
            {
                CallBack();
            }
        }
        /// <summary>
        /// 对Python进行For循环
        /// </summary>
        /// <param name="start">开始值</param>
        /// <param name="to">结束值</param>
        /// <param name="CallBack">Python回调函数</param>
        public static void For(long start, long to, Action  CallBack)
        {
            For(start, to, 1, CallBack);
        }
        /// <summary>
        /// 对Python进行For循环
        /// </summary>
        /// <param name="to">结束值</param>
        /// <param name="CallBack">Python回调</param>
        public static void For(long to, Action  CallBack)
        {
            For(0, to, 1, CallBack);
        }
        /// <summary>
        /// 对List进行For循环
        /// </summary>
        /// <typeparam name="T">List中的参数类型</typeparam>
        /// <param name="list">要循环的List</param>
        /// <param name="CallBack">Python回调函数</param>
        public static void For<T>(List<T> list,CallBack<T,List<T>> CallBack)
        {
            int length = list.Count;
            for (int i = 0; i <length; i++)
            {
                var value=list[i];
                CallBack(ref value, ref list);
            }          
        }

    }
}
